package com.polaris.live.adapter

import android.util.LayoutDirection
import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.common.adapter.BaseAdapter
import com.polaris.live.common.ext.autoDp
import com.polaris.live.common.ext.formatNumberWithK
import com.polaris.live.databinding.AdapterGamePlayWinBinding
import com.polaris.live.resp.back_resp.GameRankResp
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.widget.LevelView
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * GamePlayWinAdapter 赢钱adapter
 * @author Created by 天晴 on 2024/1/19 11:30
 * @since 1.0.0
 **/
class GamePlayWinAdapter : BaseAdapter<GameRankResp, GamePlayWinAdapter.GamePlayWinHolder>(0) {

    override fun onCreateDefViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): GamePlayWinHolder {
        return GamePlayWinHolder(
            AdapterGamePlayWinBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    override fun convert(holder: GamePlayWinHolder, item: GameRankResp) {
        holder.binding.name.text = item.userBasic.nickname
        holder.binding.money.text = if (context.resources.configuration.layoutDirection == LayoutDirection.RTL) {
            "${item.amount.formatNumberWithK()}+"
        } else {
            "+${item.amount.formatNumberWithK()}"
        }
        holder.binding.acFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.userBasic.avatarFrame))
        Glide.with(context)
            .load(ImageUtils.imgPathSmall(item.userBasic.avatar))
            .transform(CircleCrop())
            .into(holder.binding.avater)
        holder.binding.vipView.setVipLevel(item.userBasic.vipLevel, 32.autoDp, 11.autoDp)
        holder.binding.levelView.setRichCharmBySexLevel(
            item.userBasic.sex,
            item.userBasic.richs,
            item.userBasic.charms,
            LevelView.LEVEL_VIEW_SUPER_SMALL
        )
    }

    inner class GamePlayWinHolder(val binding: AdapterGamePlayWinBinding) :
        BaseViewHolder(binding.root)
}